package com.htgd.gardenexpo.config;
import com.alibaba.fastjson.JSONObject;
import com.htgd.gardenexpo.entity.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseEntity<CommonResult<JSONObject>> handleException(Exception e) {
        // 记录日志或其他处理逻辑
        CommonResult<JSONObject> result = new CommonResult<>();
        result.setCode(500);
        result.setMessage("服务器内部错误: " + e.getMessage());
        log.info("服务器内部错误: " + e.getMessage());
        return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
